/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package dataflowScheme.impl;

import dataflowScheme.Block;
import dataflowScheme.Connection;
import dataflowScheme.DataflowSchemePackage;
import dataflowScheme.PE;

import dataflowScheme.Stopper;
import dataflowScheme.Trigger;
import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Block</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link dataflowScheme.impl.BlockImpl#getEntity <em>Entity</em>}</li>
 *   <li>{@link dataflowScheme.impl.BlockImpl#getConnection <em>Connection</em>}</li>
 *   <li>{@link dataflowScheme.impl.BlockImpl#getTrigger <em>Trigger</em>}</li>
 *   <li>{@link dataflowScheme.impl.BlockImpl#getStopper <em>Stopper</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BlockImpl extends EObjectImpl implements Block {
	/**
	 * The cached value of the '{@link #getEntity() <em>Entity</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEntity()
	 * @generated
	 * @ordered
	 */
	protected EList<PE> entity;

	/**
	 * The cached value of the '{@link #getConnection() <em>Connection</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getConnection()
	 * @generated
	 * @ordered
	 */
	protected EList<Connection> connection;

	/**
	 * The cached value of the '{@link #getTrigger() <em>Trigger</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTrigger()
	 * @generated
	 * @ordered
	 */
	protected Trigger trigger;

	/**
	 * The cached value of the '{@link #getStopper() <em>Stopper</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStopper()
	 * @generated
	 * @ordered
	 */
	protected EList<Stopper> stopper;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BlockImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DataflowSchemePackage.Literals.BLOCK;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PE> getEntity() {
		if (entity == null) {
			entity = new EObjectContainmentEList<PE>(PE.class, this, DataflowSchemePackage.BLOCK__ENTITY);
		}
		return entity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Connection> getConnection() {
		if (connection == null) {
			connection = new EObjectContainmentEList<Connection>(Connection.class, this, DataflowSchemePackage.BLOCK__CONNECTION);
		}
		return connection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Trigger getTrigger() {
		return trigger;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTrigger(Trigger newTrigger, NotificationChain msgs) {
		Trigger oldTrigger = trigger;
		trigger = newTrigger;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DataflowSchemePackage.BLOCK__TRIGGER, oldTrigger, newTrigger);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTrigger(Trigger newTrigger) {
		if (newTrigger != trigger) {
			NotificationChain msgs = null;
			if (trigger != null)
				msgs = ((InternalEObject)trigger).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - DataflowSchemePackage.BLOCK__TRIGGER, null, msgs);
			if (newTrigger != null)
				msgs = ((InternalEObject)newTrigger).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - DataflowSchemePackage.BLOCK__TRIGGER, null, msgs);
			msgs = basicSetTrigger(newTrigger, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DataflowSchemePackage.BLOCK__TRIGGER, newTrigger, newTrigger));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Stopper> getStopper() {
		if (stopper == null) {
			stopper = new EObjectContainmentEList<Stopper>(Stopper.class, this, DataflowSchemePackage.BLOCK__STOPPER);
		}
		return stopper;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DataflowSchemePackage.BLOCK__ENTITY:
				return ((InternalEList<?>)getEntity()).basicRemove(otherEnd, msgs);
			case DataflowSchemePackage.BLOCK__CONNECTION:
				return ((InternalEList<?>)getConnection()).basicRemove(otherEnd, msgs);
			case DataflowSchemePackage.BLOCK__TRIGGER:
				return basicSetTrigger(null, msgs);
			case DataflowSchemePackage.BLOCK__STOPPER:
				return ((InternalEList<?>)getStopper()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DataflowSchemePackage.BLOCK__ENTITY:
				return getEntity();
			case DataflowSchemePackage.BLOCK__CONNECTION:
				return getConnection();
			case DataflowSchemePackage.BLOCK__TRIGGER:
				return getTrigger();
			case DataflowSchemePackage.BLOCK__STOPPER:
				return getStopper();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DataflowSchemePackage.BLOCK__ENTITY:
				getEntity().clear();
				getEntity().addAll((Collection<? extends PE>)newValue);
				return;
			case DataflowSchemePackage.BLOCK__CONNECTION:
				getConnection().clear();
				getConnection().addAll((Collection<? extends Connection>)newValue);
				return;
			case DataflowSchemePackage.BLOCK__TRIGGER:
				setTrigger((Trigger)newValue);
				return;
			case DataflowSchemePackage.BLOCK__STOPPER:
				getStopper().clear();
				getStopper().addAll((Collection<? extends Stopper>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DataflowSchemePackage.BLOCK__ENTITY:
				getEntity().clear();
				return;
			case DataflowSchemePackage.BLOCK__CONNECTION:
				getConnection().clear();
				return;
			case DataflowSchemePackage.BLOCK__TRIGGER:
				setTrigger((Trigger)null);
				return;
			case DataflowSchemePackage.BLOCK__STOPPER:
				getStopper().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DataflowSchemePackage.BLOCK__ENTITY:
				return entity != null && !entity.isEmpty();
			case DataflowSchemePackage.BLOCK__CONNECTION:
				return connection != null && !connection.isEmpty();
			case DataflowSchemePackage.BLOCK__TRIGGER:
				return trigger != null;
			case DataflowSchemePackage.BLOCK__STOPPER:
				return stopper != null && !stopper.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //BlockImpl
